import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

enum ViewState {
  /*空闲*/
  Idle,
  /*加载*/
  Busy,
}

/*VM 视图模型基类 */
class BaseViewModel extends ChangeNotifier {
  late bool _disponsed = false;

  ViewState _state = ViewState.Idle;
  ViewState get state => _state;

  BaseViewModel();

  void setState(ViewState vm) {
    _state = vm;
    notifyListeners();
  }

  @override
  void notifyListeners() {
    // TODO: implement notifyListeners
    if (!_disponsed) {
      super.notifyListeners();
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _disponsed = true;
  }
}
